package com.ttt.radioapp_core.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ttt.radioapp_core.R;
import com.ttt.radioapp_core.radioprogramacion.entities.Programa;

public class ProgramaAdapter extends BaseAdapter {
	private List<Programa> programas;
	private Context context;

	public ProgramaAdapter(List<Programa> programas, Context context) {
		super();
		this.programas = programas;
		this.context = context;
	}

	@Override
	public int getCount() {
		return this.programas.size();
	}

	@Override
	public Object getItem(int position) {
		return this.programas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View mView = convertView;
		if (mView == null) {
			LayoutInflater vi = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mView = vi.inflate(R.layout.programacion_programa_item_row, null);
		}

		TextView tv_nombre = (TextView) mView
				.findViewById(R.id.iconrow_rss_titulo);
		TextView tv_descripcion = (TextView) mView
				.findViewById(R.id.iconrow_rss_descripcion);
		TextView tv_hora = (TextView) mView.findViewById(R.id.iconrow_rss_hora);

		Programa programa = programas.get(position);
		if (programa != null) {
			tv_nombre.setText(programa.getNombre_programa());
			tv_hora.setText(programa.getHorario());
			tv_descripcion.setText(programa.getDescripcion_programa());
		}

		return mView;
	}

}
